﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


using System.Drawing;
using System.Globalization;
using MapCenterSystem.DataInfo;
using MapCenterSytem.Process;
using System.Collections.Generic;
using MapCenterSystem.Utility;


using System.Threading;
using System.Resources;

namespace MobiMap.MasterPage
{
    public partial class Admin : System.Web.UI.MasterPage
    {
        ResourceManager rm;
        CultureInfo ci;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["mobimap_admin"] != null)
            {
                //Session["mobimap_admin"] = true;
                if ((bool)Session["mobimap_admin"] == true)
                {
                    //HtmlControl divLock = (HtmlControl)Master.FindControl("divLock");
                    divLock.Style["display"] = "none";
                }
            }

            imgMap.Attributes.Add("onload", "changedImageMap();");

            if (Session["MAP"] != null)
            {
                MapInfoEx map = (MapInfoEx)Session["MAP"];
                cmbMode.SelectedIndex = map.MapType;
            }

            //Language
            SetLanguage();
        }

        public void SetLanguage()
        {
            rm = new ResourceManager("Resources.SiteMap", System.Reflection.Assembly.Load("App_GlobalResources"));
            if (Request.Cookies["language"] != null)
            {
                string language = Request.Cookies["language"].Value;
                Thread.CurrentThread.CurrentCulture = new CultureInfo(language);
                LoadString(Thread.CurrentThread.CurrentCulture);

                return;
            }

            //Defaut language is Vietnamese
            Thread.CurrentThread.CurrentCulture = new CultureInfo("vi-VN");
            ci = Thread.CurrentThread.CurrentCulture;
            LoadString(ci);
        }

        public void LoadString(CultureInfo ci)
        {
            cmbMode.Items[0].Text = rm.GetString("Mode_Map", ci);
            cmbMode.Items[1].Text = rm.GetString("Mode_Satellite", ci);
            cmbMode.Items[2].Text = rm.GetString("Mode_Hybrid", ci);

            Service.InnerHtml = rm.GetString("Admin_Tab_Place", ci);
            ServiceType.InnerHtml = rm.GetString("Admin_Tab_PlaceType", ci);
            btnSearch.Text = rm.GetString("Admin_SearchPlace", ci);            
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string request = StringHelper.StandardizeString(txtSearchService.Text);
            if (request != string.Empty)
            {
                Response.Redirect("ResultService.aspx?keyword=" + request);
            }
        }
    }
}
